package com.qianfeng.yime.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.qianfeng.yime.CityChooseActivity;
import com.qianfeng.yime.R;
import com.qianfeng.yime.model.City;
import com.qianfeng.yime.util.CurrentSingleton;

/**
 * Created by Fcy on 2015/3/10.
 */
public class JianZhiFragment extends Fragment implements View.OnClickListener {

    private TextView citySidelineCurrent;
    private LinearLayout cityCurrent;
    private LinearLayout sidelineType;
    private LinearLayout rangeType;
    private LinearLayout orderType;
    private TextView cityLocation;
    private ImageView cityLocationRefresh;
    private PullToRefreshListView cityList;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View ret = inflater.inflate(R.layout.fragment_jianzhi, container, false);

        citySidelineCurrent = (TextView) ret.findViewById(R.id.text_sideline_current_city);
        cityCurrent = (LinearLayout) ret.findViewById(R.id.layout_city_choose);
        sidelineType = (LinearLayout) ret.findViewById(R.id.layout_sideline_type_choose);
        rangeType = (LinearLayout) ret.findViewById(R.id.layout_range_choose);
        orderType = (LinearLayout) ret.findViewById(R.id.layout_order_choose);
        cityLocation = (TextView) ret.findViewById(R.id.text_location_city);
        cityLocationRefresh = (ImageView) ret.findViewById(R.id.img_city_refresh);
        cityList = (PullToRefreshListView) ret.findViewById(R.id.list_refresh_sideline);

        initSidelineCurrentCity();

        cityCurrent.setOnClickListener(this);

        return ret;
    }

    @Override
    public void onResume() {
        super.onResume();
        initSidelineCurrentCity();
    }

    private void initSidelineCurrentCity() {
        CurrentSingleton singleton = CurrentSingleton.getInstance();
        City currentCity = singleton.getCurrentCity();
        if (currentCity != null) {
            String name = currentCity.getName();
            citySidelineCurrent.setText(name);
        }
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id){
            case R.id.layout_city_choose:
                //TODO 城市选择按钮
                Intent intent = new Intent(getActivity(), CityChooseActivity.class);
                startActivity(intent);
                break;
            case R.id.layout_sideline_type_choose:
                //TODO 招聘类型选择按钮
                break;
            case R.id.layout_range_choose://
                //TODO 范围选择按钮
                break;
            case R.id.layout_order_choose:
                //TODO 排序类型选择按钮
                break;
            case R.id.img_city_refresh:
                //TODO 刷新当前定位城市按钮
                break;
        }
    }
}